//
//  HomeCenterPage.swift
//  Uber
//
//  Created by chen on 16/3/14.
//  Copyright © 2016年 chen. All rights reserved.
//

import UIKit

class HomeCenterPage: FxBasePage,BMKMapViewDelegate,BMKLocationServiceDelegate{
    var leftView:UIView!
    var backControl:UIControl!
    var showingLeft:Bool!
    var centerPage:UserCenterPage?
    var mapView:BMKMapView!
    var locService:BMKLocationService!
    var userCoordinate:CLLocationCoordinate2D!
    var point:BMKPointAnnotation!
    var textLabel: UILabel!
    
    @IBOutlet var bottomView:UIView!
    @IBOutlet var bottomImageView:UIImageView!
    @IBOutlet var carButton:UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()
        addBackControl()
        addBaiduMap()
        setNavigationItem("account_icon_up.png", selector: Selector("doShowLeft"), isRight: false)
        self.navigationItem.titleView = UIImageView(image: UIImage(named: "logo_uber_grey_zh_CN.png"))
        //将这个视图放在前面
        self.view.bringSubviewToFront(bottomView)
        self.doSwapButton(carButton)
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
        showingLeft = false
    }
    override func viewWillAppear(animated: Bool) {
        mapView.viewWillAppear()
        locService.delegate = self
        mapView.delegate = self
    }
    override func viewWillDisappear(animated: Bool) {
        mapView.viewWillDisappear()
        mapView.delegate = nil
    }
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        self.addLeftView()
        self.addUserCenterView()
    }
    @IBAction func doSwapButton(sender:UIButton){
        print(sender.tag)
        if textLabel != nil{
            self.textLabel.removeFromSuperview()
        }
        //这里不能使用bounds
        self.textLabel = UILabel(frame: CGRect(x: sender.frame.origin.x, y: sender.frame.origin.y - 16 , width: 40, height:10 ))
        switch sender.tag{
        case 1:
            textLabel.text = "人民优步"
            textLabel.font = UIFont(name: "Helvetica", size: 10)
            break
        case 2:
            textLabel.text = "高级优步"
            textLabel.font = UIFont(name: "Helvetica", size: 10)
            break
        case 3:
            textLabel.text = "奢华优步"
            textLabel.font = UIFont(name: "Helvetica", size: 10)
            break
        case 4:
            textLabel.text = "豪华优步"
            textLabel.font = UIFont(name: "Helvetica", size: 10)
            break
        default:
            
            break
        }
        
        for index in 1 ..< 5{
            let button = self.view.viewWithTag(index) as! UIButton
            button.setBackgroundImage(UIImage(named: ""), forState: .Normal)
            
        }
        let button = self.view.viewWithTag(sender.tag) as! UIButton
        button.setBackgroundImage(UIImage(named: "CarBtn.png"), forState: .Normal)
        print(button.frame)
        print(button.frame.origin.x + button.frame.origin.y)
        
        self.bottomImageView.addSubview(textLabel)
    }
}
